package org.domain.jpaSample.session;

import javax.persistence.EntityManager;

import model.person.Person;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.international.StatusMessages;
import org.jboss.seam.log.Log;

import test.TestManyToMany;
import test.TestOneToMany;
import test.TestOneToOne;
import test.TestPerson;


@Scope(ScopeType.CONVERSATION)
@Name("sampleAction")
public class SampleAction {
	@Logger
	private Log log;

	@In
	StatusMessages statusMessages;
	@In
	private EntityManager entityManager;

	private TestOneToOne testOneToOne = new TestOneToOne(null);

	private TestOneToMany testOneToMany = new TestOneToMany(null);

	private TestManyToMany testManyToMany = new TestManyToMany(null);
	
	private TestPerson testPerson = new TestPerson(null);

	public void testOneToOne() {
		// implement your business logic here
		log.info("sampleAction.testOneToOne() action called");

		testOneToOne.setEntityManager(this.entityManager);


		// delete HusbandAndWife
		//testOneToOne.deleteHusbandAndWife();

		// deleteWife
		// testOneToOne.deleteWife();

		// add
		testOneToOne.add();
		
//		testOneToOne.updateWife(testOneToOne.getLastWifeId());
//
//		testOneToOne.updateHusband(testOneToOne.getLastHusbandId());
		
		testOneToOne.updateHusbandAndWife(testOneToOne.getLastHusbandId());

		statusMessages.add("testOneToOne");
	}
	
	public void testOneToMany() {
		// implement your business logic here
		log.info("sampleAction.testOneToMany() action called");
		
		testOneToMany.setEntityManager(this.entityManager);

				// delete
				testOneToMany.deleteAll();

		//		// deleteA
		//		testOneToMany.deleteLastA();
		/*
		 * // // add testOneToMany.add();
		 * 
		 * // update testOneToMany.updateAll();
		 */
		statusMessages.add("testOneToMany");
	}
	
	public void testManyToMany() {
		// implement your business logic here
		log.info("sampleAction.testManyToMany() action called");
		
		testManyToMany.setEntityManager(this.entityManager);
		
		/*
		
		//issert
		testManyToMany.add();
		
		//select
		Student s = testManyToMany.getStudent(1);
		System.out.println(s.getSName());
		
		//update
		testManyToMany.update();
		
		//delete
		testManyToMany.delete();
		
		
		*/
		
		
		
		
		//testManyToMany.deleteAll();
		//testManyToMany.deleteTeacher(23);
		//testManyToMany.deleteAllTeacher();
	
		//testManyToMany.deleteStudentById(45);
		
		testManyToMany.deleteAll();
//		testManyToMany.deleteAllStudent();
//		
		testManyToMany.add();
		
//		testManyToMany.updateStudent(testManyToMany.getLastStudentId());
//		testManyToMany.updateTeacher(testManyToMany.getLastTeacherId());
//		testManyToMany.updateAllStudent();
//		testManyToMany.updateAllTeacher();
		testManyToMany.updateAllStudentAndTeacher();
		
		
		statusMessages.add("testManyToMany");
	}

	
	public void testPerson() {
		// implement your business logic here
		log.info("sampleAction.testPerson() action called");
		
		testPerson.setEntityManager(this.entityManager);
		
		testPerson.add();
		
		testPerson.updatePerson();
		
		Person p=testPerson.getPerson();
		System.out.println(p.getPMemo());
		
		
		statusMessages.add("testPerson");
	}
	
	
	
	
	
	// add additional action methods
    
}
